package com.bdqn.t382.lx.filter;

import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.filter.PropertyPreFilter;

import java.util.Set;

public class FastJson2SensitivePropFilter implements PropertyPreFilter {
    /**
     * 通过构造器注入需要排除的属性集合
     */
    public FastJson2SensitivePropFilter(Set<String> excludes) {
        this.excludes = excludes;
    }

    private Set<String> excludes;

    @Override
    public boolean process(JSONWriter jsonWriter, Object obj, String propertyName) {
        if (excludes == null) {
            // 没有排除的属性，直接允许
            return true;
        }
        // 不包含在 excludes 中的属性才需要序列化
        boolean isNeed = !excludes.contains(propertyName);
        return isNeed;
    }
}
